#include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node * next;
};
struct node * build(struct node * root){
    int x;
    scanf("%d",&x);
    if(x==0)return NULL;
    root=(struct node *)malloc(sizeof(struct node));
    root->data=x;
    root->next=build(root->next);
    return root;
}
void pinrt(struct node *root){
    while(root!=NULL){
        printf("%d",root->data);
        root=root->next;
    }
}
struct node *del(int x,struct node *now,struct node *fa,struct node *root){
     while(now!=NULL){
        if(now->data==x){
           if(now!=root){
            struct node *temp=now;
            fa->next=now->next;
            now=now->next;
            free(temp);
            continue;
           }
           else{
            root=root->next;
            free(now);
            now=root;
            fa=root;
            continue;
           }
        }
        fa=now;
        now=now->next;
    
    }
    return root;
}
int main(){
    int x;
    struct node * root;
    root=build(root);
    scanf("%d",&x);
    root=del(x,root,root,root);
    pinrt(root);
    return 0;
}